home *** CD-ROM | disk | FTP | other *** search
- package horst;
-
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Rectangle;
- import java.awt.Shape;
- import java.util.Vector;
-
- public class TableRow extends View {
- int[] m_colWidths;
- CellBorder[] m_cellBorders;
- Color m_bgColor;
- int m_valign;
- int m_prefWidth = -1;
- int m_prefHeight = -1;
- int m_minWidth = -1;
- int m_minHeight = -1;
- TableView m_tableView;
-
- public TableRow(View parent, Element e, HTMLPane container) {
- super(parent, e, container);
- }
-
- protected void computeCellBorders() {
- this.m_cellBorders = new CellBorder[super.m_children.length];
- int cellSpacing = this.m_tableView.m_cellSpacing;
-
- for(int i = 0; i < super.m_children.length; ++i) {
- CellBorder r = new CellBorder(this);
- TableCell cell = (TableCell)super.m_children[i];
- Rectangle bounds = cell.getBounds();
- ((Rectangle)r).setBounds(bounds);
- this.m_cellBorders[i] = r;
- this.m_cellBorders[i].bPaint = false;
- View[] children = cell.m_children;
-
- for(int h = 0; h < children.length; ++h) {
- if (children[h].isDisplayableView()) {
- this.m_cellBorders[i].bPaint = true;
- break;
- }
- }
- }
-
- }
-
- protected View elementToView(Element e) {
- if (super.m_elem == e) {
- return this;
- } else {
- for(int i = 0; i < super.m_children.length; ++i) {
- View v = super.m_children[i].elementToView(e);
- if (v != null) {
- return v;
- }
- }
-
- return null;
- }
- }
-
- protected int getBiggestRowSpan() {
- int result = 1;
-
- for(int i = 0; i < super.m_children.length; ++i) {
- TableCell cell = (TableCell)super.m_children[i];
- result = Math.max(result, cell.m_rowSpan);
- }
-
- return result;
- }
-
- protected TableCell getCell(int i) {
- return super.m_children != null && i < super.m_children.length ? (TableCell)super.m_children[i] : null;
- }
-
- protected int getHeightSpec() {
- int heightSpec = -1;
-
- for(int i = 0; i < super.m_children.length; ++i) {
- TableCell cell = (TableCell)super.m_children[i];
- if (cell.m_height >= 0) {
- heightSpec = Math.max(heightSpec, cell.m_height);
- }
- }
-
- return heightSpec;
- }
-
- protected int getMinimumSpan(int axis) {
- if (axis != 1) {
- return 0;
- } else if (this.m_minWidth != -1) {
- return this.m_minWidth;
- } else {
- int span = 0;
-
- for(int i = 0; i < super.m_children.length; ++i) {
- span += super.m_children[i].getMinimumSpan(1);
- }
-
- span += (super.m_children.length - 1) * this.m_tableView.m_cellSpacing;
- this.m_minWidth = span;
- return this.m_minWidth;
- }
- }
-
- protected int getPreferredSpan(int axis) {
- if (axis != 1) {
- return 0;
- } else if (this.m_prefWidth != -1) {
- return this.m_prefWidth;
- } else {
- int m_prefWidth = 0;
-
- for(int i = 0; i < super.m_children.length; ++i) {
- m_prefWidth += super.m_children[i].getPreferredSpan(1);
- }
-
- m_prefWidth += (super.m_children.length - 1) * this.m_tableView.m_cellSpacing;
- return m_prefWidth;
- }
- }
-
- protected TableCell getTableColumn(int col) {
- TableCell tableCell = null;
-
- for(int i = 0; i < super.m_children.length; ++i) {
- TableCell cell = (TableCell)super.m_children[i];
- if (cell != null) {
- if (cell.m_startColumn == col) {
- if (cell.m_endColumn == cell.m_startColumn) {
- tableCell = cell;
- }
- break;
- }
-
- if (cell.m_endColumn >= col) {
- break;
- }
- }
- }
-
- return tableCell;
- }
-
- protected Rectangle increaseHeight(int increaseY) {
- int rowHeight = 0;
-
- for(int i = 0; i < super.m_children.length; ++i) {
- TableCell cell = (TableCell)super.m_children[i];
- if (cell.m_rowSpan == 1) {
- cell.increaseHeight(increaseY);
- rowHeight = Math.max(rowHeight, cell.getBounds().height);
- }
- }
-
- super.m_bounds.height = rowHeight;
- return super.m_bounds;
- }
-
- protected void init() {
- this.m_tableView = (TableView)super.m_parent;
- this.m_bgColor = Utilities.setColorProperty(this.m_tableView.m_bgColor, "bgcolor", super.m_elem.getAttributes());
- super.m_alignment = Utilities.setAlignmentProperty(false, 0, "align", super.m_elem.getAttributes());
- this.m_valign = Utilities.setAlignmentProperty(true, 1, "valign", super.m_elem.getAttributes());
- }
-
- protected int[] layoutMultiRowCells(int x, int y, int width, int[] rowHeights, LayoutInfo info) {
- int cellSpacing = this.m_tableView.m_cellSpacing;
- int rowHeight = 0;
-
- for(int i = 0; i < super.m_children.length; ++i) {
- TableCell cell = (TableCell)super.m_children[i];
- if (cell.m_rowSpan >= 2) {
- int colspan = cell.m_colSpan;
- int startCol = cell.m_startColumn;
- int endCol = cell.m_endColumn;
- int xPos = x;
-
- for(int j = 0; j < startCol; ++j) {
- xPos += this.m_colWidths[j] + cellSpacing;
- }
-
- int layoutWidth = 0;
-
- for(int j = startCol; j <= endCol; ++j) {
- layoutWidth += this.m_colWidths[j];
- }
-
- if (colspan > 1) {
- layoutWidth += (colspan - 1) * cellSpacing;
- }
-
- LayoutInfo subInfo = new LayoutInfo();
- subInfo.bPaginate = info.bPaginate;
- subInfo.pageBreak = info.pageBreak;
- Rectangle bounds = cell.layout(xPos, y, layoutWidth, subInfo);
- int startRow = cell.m_startRow;
- int endRow = cell.m_endRow;
- int span = 0;
-
- for(int j = startRow; j <= endRow; ++j) {
- span += rowHeights[j];
- }
-
- if (cell.m_rowSpan > 1) {
- int nDefinedRows = this.m_tableView.m_nDefinedRows;
- if (startRow < nDefinedRows - 1 && endRow >= nDefinedRows - 1) {
- int nValidRowsSpanned = nDefinedRows - startRow;
- if (nValidRowsSpanned > 0 && cellSpacing > 0) {
- span += (nValidRowsSpanned - 1) * cellSpacing;
- }
- } else if (cellSpacing > 0) {
- span += (cell.m_rowSpan - 1) * cellSpacing;
- }
- }
-
- if (span < bounds.height) {
- int diff = bounds.height - span;
- boolean bCheckSpecs = true;
- int[] heightSpecs = this.m_tableView.m_rowHeightSpecs;
-
- while(diff > 0) {
- for(int row = startRow; row <= endRow && diff > 0; ++row) {
- if (!bCheckSpecs || heightSpecs[row] < 0 || heightSpecs[row] > 0 && heightSpecs[row] > rowHeights[row]) {
- this.m_tableView.increaseRowHeight(row, 1);
- int var10002 = rowHeights[row]++;
- --diff;
- }
- }
-
- bCheckSpecs = false;
-
- for(int row = startRow; row <= endRow && diff > 0; ++row) {
- if (heightSpecs[row] < 0 || heightSpecs[row] > 0 && heightSpecs[row] > rowHeights[row]) {
- bCheckSpecs = true;
- break;
- }
- }
- }
- }
- }
- }
-
- int h = 0;
- View[] vws = this.m_tableView.m_children;
-
- for(int i = 0; i < vws.length; ++i) {
- TableRow r = (TableRow)vws[i];
- if (r == this) {
- h = rowHeights[i];
- break;
- }
- }
-
- super.m_bounds.height = h;
- int w = 0;
-
- for(int i = 0; i < this.m_colWidths.length; ++i) {
- w += this.m_colWidths[i];
- if (i != this.m_colWidths.length - 1) {
- w += cellSpacing;
- }
- }
-
- super.m_bounds.width = w;
- return rowHeights;
- }
-
- protected Rectangle layoutSingleRowCells(int x, int y, int width, LayoutInfo info) {
- super.m_bounds = new Rectangle(x, y, 0, 0);
- int cellSpacing = this.m_tableView.m_cellSpacing;
- int rowWidth = 0;
- int rowHeight = 0;
- int nColumns = this.m_tableView.m_nColumns;
-
- for(int i = 0; i < super.m_children.length; ++i) {
- TableCell cell = (TableCell)super.m_children[i];
- if (cell.m_rowSpan <= 1) {
- int colspan = cell.m_colSpan;
- int startCol = cell.m_startColumn;
- int endCol = cell.m_endColumn;
- int xPos = x;
-
- for(int j = 0; j < startCol; ++j) {
- xPos += this.m_colWidths[j] + cellSpacing;
- }
-
- int layoutWidth = 0;
-
- for(int j = startCol; j <= endCol; ++j) {
- layoutWidth += this.m_colWidths[j];
- }
-
- if (colspan > 1) {
- layoutWidth += (colspan - 1) * cellSpacing;
- }
-
- LayoutInfo subInfo = new LayoutInfo();
- subInfo.bPaginate = false;
- Rectangle bounds = cell.layout(xPos, y, layoutWidth, subInfo);
- rowWidth += bounds.width;
- if (endCol != nColumns - 1) {
- rowWidth += cellSpacing;
- }
-
- Math.max(layoutWidth, bounds.width);
- if (cell.m_rowSpan == 1) {
- rowHeight = Math.max(rowHeight, bounds.height);
- }
- }
- }
-
- super.m_bounds = new Rectangle(x, y, rowWidth, rowHeight);
- return super.m_bounds;
- }
-
- protected void makeChildren(ViewFactory factory) {
- Element elem = super.m_elem;
- int nCount = elem.getElementCount();
- Vector temp = new Vector();
- int tableColumn = 0;
-
- for(int i = 0; i < nCount; ++i) {
- Element childElement = elem.getElementAt(i);
- int type = childElement.getType();
- if (type == 5 || type == 4) {
- TableCell cell = new TableCell(this, this.m_tableView, childElement, super.m_container);
- cell.setTableColumns(tableColumn);
- tableColumn += cell.m_colSpan;
- temp.addElement(cell);
- }
- }
-
- super.m_children = new View[temp.size()];
- temp.copyInto(super.m_children);
-
- for(int i = 0; i < super.m_children.length; ++i) {
- super.m_children[i].makeChildren(factory);
- }
-
- }
-
- protected View modelToView(int pos) {
- if (pos >= super.m_elem.m_p0 && pos <= super.m_elem.m_p1) {
- return this;
- } else {
- for(int i = 0; i < super.m_children.length; ++i) {
- View v = super.m_children[i].modelToView(pos);
- if (v != null) {
- return v;
- }
- }
-
- return null;
- }
- }
-
- protected void move(int x, int y, boolean bMoveFloaters) {
- for(int i = 0; i < super.m_children.length; ++i) {
- super.m_children[i].move(x, y, bMoveFloaters);
- }
-
- if (this.m_cellBorders != null) {
- for(int i = 0; i < this.m_cellBorders.length; ++i) {
- CellBorder var10000 = this.m_cellBorders[i];
- var10000.x += x;
- var10000 = this.m_cellBorders[i];
- var10000.y += y;
- }
- }
-
- Rectangle var7 = super.m_bounds;
- var7.x += x;
- var7 = super.m_bounds;
- var7.y += y;
- }
-
- protected boolean occupies(int row, int col) {
- for(int i = 0; i < super.m_children.length; ++i) {
- TableCell cell = (TableCell)super.m_children[i];
- if (cell.occupies(row, col)) {
- return true;
- }
- }
-
- return false;
- }
-
- protected int pageBreakAdjust(LayoutInfo info) {
- Rectangle origBounds = new Rectangle(super.m_bounds);
- int maxCellHeight = 0;
-
- for(int i = 0; i < super.m_children.length; ++i) {
- TableCell cell = (TableCell)super.m_children[i];
- cell.pageBreakAdjust(info);
- maxCellHeight = Math.max(maxCellHeight, cell.m_cellBounds.height);
- }
-
- for(int i = 0; i < super.m_children.length; ++i) {
- TableCell cell = (TableCell)super.m_children[i];
- if (maxCellHeight > cell.m_cellBounds.height) {
- cell.increaseHeight(maxCellHeight - cell.m_cellBounds.height);
- }
- }
-
- super.m_bounds.height = maxCellHeight;
- this.computeCellBorders();
- return super.m_bounds.height - origBounds.height;
- }
-
- public void paint(Graphics g, Shape alloc) {
- for(int i = 0; i < super.m_children.length; ++i) {
- super.m_children[i].paint(g, alloc);
- }
-
- this.paintCellBorders(g);
- }
-
- protected void paintCellBorders(Graphics g) {
- if (this.m_cellBorders != null && this.m_tableView.m_borderSize > 0) {
- Color oldColor = g.getColor();
-
- for(int i = 0; i < this.m_cellBorders.length; ++i) {
- CellBorder r = this.m_cellBorders[i];
- if (r != null && r.bPaint) {
- g.setColor(Utilities.getDarkBorderColor());
- g.drawLine(r.x, r.y, r.x + r.width - 1, r.y);
- g.drawLine(r.x, r.y, r.x, r.y + r.height - 1);
- g.setColor(Utilities.getBrightBorderColor());
- g.drawLine(r.x, r.y + r.height - 1, r.x + r.width - 1, r.y + r.height - 1);
- g.drawLine(r.x + r.width - 1, r.y, r.x + r.width - 1, r.y + r.height - 1);
- }
- }
-
- g.setColor(oldColor);
- }
-
- }
-
- protected void paintFocusBox(Graphics g, Shape alloc) {
- for(int i = 0; i < super.m_children.length; ++i) {
- super.m_children[i].paintFocusBox(g, alloc);
- }
-
- }
-
- protected int[] setCellHeights(int[] rowHeights, LayoutInfo info) {
- for(int i = 0; i < super.m_children.length; ++i) {
- TableCell cell = (TableCell)super.m_children[i];
- int cellHeight = cell.getBounds().height;
- int rowspan = cell.m_rowSpan;
- if (rowspan <= 1) {
- int rowHeight = rowHeights[cell.m_startRow];
- if (rowHeight > cellHeight) {
- cell.increaseHeight(rowHeight - cellHeight);
- }
- } else {
- int targetHeight = 0;
-
- for(int j = cell.m_startRow; j <= cell.m_endRow; ++j) {
- targetHeight += rowHeights[j];
- }
-
- int cellSpacing = this.m_tableView.m_cellSpacing;
- int startRow = cell.m_startRow;
- int endRow = cell.m_endRow;
- int nDefinedRows = this.m_tableView.m_nDefinedRows;
- if (startRow < nDefinedRows - 1 && endRow >= nDefinedRows - 1) {
- int nValidRowsSpanned = nDefinedRows - startRow;
- if (nValidRowsSpanned > 0 && cellSpacing > 0) {
- targetHeight += (nValidRowsSpanned - 1) * cellSpacing;
- }
- } else if (cellSpacing > 0) {
- targetHeight += (cell.m_rowSpan - 1) * cellSpacing;
- }
-
- if (targetHeight > cellHeight) {
- cell.increaseHeight(targetHeight - cellHeight);
- }
- }
- }
-
- int[] rowHeightAdjustments = new int[rowHeights.length];
- int maxCellHeight = 0;
-
- for(int i = 0; i < super.m_children.length; ++i) {
- TableCell cell = (TableCell)super.m_children[i];
- int pagingAdjustment = cell.doCellVerticalAlignment(info);
- maxCellHeight = Math.max(maxCellHeight, cell.getBounds().height);
- if (pagingAdjustment > 0) {
- this.m_tableView.increasePreviousCellHeights(this, pagingAdjustment);
- int[] rowHeightValues = new int[rowHeights.length];
- int space = pagingAdjustment;
-
- while(space > 0) {
- for(int j = cell.m_startRow; j <= cell.m_endRow && space > 0; ++j) {
- int var10002 = rowHeightValues[j]++;
- --space;
- }
- }
-
- for(int j = cell.m_startRow; j <= cell.m_endRow; ++j) {
- rowHeightAdjustments[j] = Math.max(rowHeightAdjustments[j], rowHeightValues[j]);
- }
- }
- }
-
- for(int row = 0; row < rowHeightAdjustments.length; ++row) {
- if (rowHeightAdjustments[row] > 0) {
- rowHeights[row] += rowHeightAdjustments[row];
- TableRow rv = this.m_tableView.getRow(row + 1);
- if (rv != null) {
- this.m_tableView.moveRows(rowHeightAdjustments[row], rv);
- }
- }
- }
-
- return rowHeights;
- }
-
- protected ElementViewInfo viewToModel(int x, int y) {
- ElementViewInfo info = null;
-
- for(int i = 0; i < super.m_children.length; ++i) {
- if (super.m_children[i].contains(x, y)) {
- info = super.m_children[i].viewToModel(x, y);
- if (info != null) {
- break;
- }
- }
- }
-
- return info;
- }
- }
-